# coding: utf-8

from marshmallow import fields

from app.op.constant import RedPacketType
from ..extensions import ma
from app.api.utils import EmptyStrValidator


class GetBidPointRedPacketSchema(ma.Schema):
    """
    created by lina at 2018.07.26
    """
    money = fields.Int()
    received_at = fields.Int()
    best_receiver = fields.Boolean(default=False)
    receiver_nickname = fields.Str()
    receiver_id = fields.Int()
    receiver_avatar = fields.Str()

get_bid_point_red_packet_schema = GetBidPointRedPacketSchema(many=True)


class BidPointRedPacketSchema(ma.Schema):
    sender_id = fields.Int()
    packet_count = fields.Int()
    total_money = fields.Int()
    remark = fields.Str()
    status = fields.Int()
    packet_type = fields.Int()
    overed_at = fields.Int()
    sender_nickname = fields.Str()
    sender_avatar = fields.Str()
    created_at = fields.Int()

bid_point_red_packet_schema = BidPointRedPacketSchema()


class SendRedPacketSchema(ma.Schema):
    """
    add by zhouhl 2018-07-26
    发红包相关参数
    """
    receiver_id = fields.Int(missing=0)
    total_money = fields.Int(
        required=True,
        error_messages={'required': '红包金额为必填'},
        validate=[
            EmptyStrValidator(error='红包金额不能为空'),
        ]
    )
    packet_count = fields.Int(
        required=True,
        error_messages={'required': '红包数量为必填'},
        validate=[
            EmptyStrValidator(error='红包数量不能为空'),
        ]
    )
    packet_type = fields.Int(missing=RedPacketType.RANDOM.value)
    remark = fields.Str()
    im_group_id = fields.Str()

send_red_packet_schema = SendRedPacketSchema()


class ReceiveRedPacketSchema(ma.Schema):
    """
    add by zhouhl 2018-07-27
    收红包相关参数
    """
    red_packet_id = fields.Int(
        required=True,
        error_messages={'required': '红包ID为必填'},
        validate=[
            EmptyStrValidator(error='红包ID不能为空'),
        ]
    )

receive_red_packet_schema = ReceiveRedPacketSchema()


class ReceiveRedPacketHistorySchema(ma.Schema):
    """
    收红包历史记录参数
    created by lina at 2018.07.28
    """
    sender_nickname = fields.Str()
    received_at = fields.Int()
    money = fields.Int()

receive_red_packet_history_schema = ReceiveRedPacketHistorySchema(many=True)


class SendRedPacketHistorySchema(ma.Schema):
    """
    发红包历史记录参数
    created by lina at 2018.07.30
    """
    packet_count = fields.Int()
    total_money = fields.Int()
    received_count = fields.Int()
    status = fields.Int()
    packet_type = fields.Int()
    sender_nickname = fields.Str()
    created_at = fields.Int()

send_red_packet_history_schema = SendRedPacketHistorySchema(many=True)
